﻿// use_1_yggl.cpp: 实现文件
//

#include "pch.h"
#include "HoManSys1.h"
#include "use_1_yggl.h"
#include "afxdialogex.h"
#include "ADOconnection.h"
#include "ygrz.h"
#include "yglz.h"
//数据库类实例化
ADOconnection con;
// use_1_yggl 对话框

IMPLEMENT_DYNAMIC(use_1_yggl, CDialogEx)

use_1_yggl::use_1_yggl(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_yggl, pParent)
	, m_name(_T(""))
	, m_sex(_T(""))
	, m_id(_T(""))
	, m_phone(_T(""))
{

}

use_1_yggl::~use_1_yggl()
{
}

void use_1_yggl::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	
	DDX_Control(pDX, IDC_COMBO1, m_combo);
	DDX_Text(pDX, IDC_EDIT1, m_name);
	DDX_Text(pDX, IDC_EDIT2, m_sex);
	DDX_Text(pDX, IDC_EDIT3, m_id);
	DDX_Text(pDX, IDC_EDIT4, m_phone);
}


BEGIN_MESSAGE_MAP(use_1_yggl, CDialogEx)
	
	ON_CBN_SELCHANGE(IDC_COMBO1, &use_1_yggl::OnCbnSelchangeCombo1)
	ON_BN_CLICKED(IDC_BUTTON1, &use_1_yggl::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &use_1_yggl::OnBnClickedButton2)
END_MESSAGE_MAP()


// use_1_yggl 消息处理程序
BOOL use_1_yggl::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	con.DBConnection();//数据库链接
	//执行查询，创建结果集
	m_pStr.CreateInstance(__uuidof(Recordset));
	CString str = _T("select staffID from staff");
	m_pStr->Open(_bstr_t(str), con.m_pCon.GetInterfacePtr(), adOpenDynamic, adLockBatchOptimistic, adCmdText);

	while (m_pStr->adoEOF == VARIANT_FALSE)
	{
		snoValue = m_pStr->GetCollect("staffID");
		str_sno = (char*)_bstr_t(snoValue);
		m_combo.AddString(str_sno);
		m_pStr->MoveNext();

	}
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}




void use_1_yggl::OnCbnSelchangeCombo1()
{
	// TODO: 在此添加控件通知处理程序代码
	con.DBConnection();
	


	int posIndex = m_combo.GetCurSel();
	CString str_sno;
	m_combo.GetLBText(posIndex, str_sno);
	CString str = _T("select * from staff where staffID = '"+ str_sno +"'");
	

	m_pname.CreateInstance(__uuidof(Recordset));
	m_pname->Open(_bstr_t(str), con.m_pCon.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
	vFieldValue = m_pname->GetCollect("stname");
	strFieldValue = (char*)_bstr_t(vFieldValue);
	m_name = strFieldValue;
	UpdateData(false);

	m_pname.CreateInstance(__uuidof(Recordset));
	m_pname->Open(_bstr_t(str), con.m_pCon.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
	vFieldValue = m_pname->GetCollect("stsex");
	strFieldValue = (char*)_bstr_t(vFieldValue);
	m_sex = strFieldValue;
	UpdateData(false);
	
	m_pname.CreateInstance(__uuidof(Recordset));
	m_pname->Open(_bstr_t(str), con.m_pCon.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
	vFieldValue = m_pname->GetCollect("stID");
	strFieldValue = (char*)_bstr_t(vFieldValue);
	m_id = strFieldValue;
	UpdateData(false);

	m_pname.CreateInstance(__uuidof(Recordset));
	m_pname->Open(_bstr_t(str), con.m_pCon.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
	vFieldValue = m_pname->GetCollect("stPhone");
	strFieldValue = (char*)_bstr_t(vFieldValue);
	m_phone = strFieldValue;
	UpdateData(false);
	/*m_pNtr.CreateInstance(__uuidof(Recordset));
	m_pNtr->Open(_bstr_t(str), con.m_pCon.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
	while (m_pNtr->adoEOF == VARIANT_FALSE)
	{
		nameValue = m_pNtr->GetCollect("stname");
		str_name = (char*)_bstr_t(nameValue);
		m_list.AddString(str_name);
		m_pNtr->MoveNext();
	}

		vFieldValue = m_psex->GetCollect("stsex");
	strFieldValue = (char*)_bstr_t(vFieldValue);
	m_sex = strFieldValue;

	vFieldValue = m_pid->GetCollect("stID");
	strFieldValue = (char*)_bstr_t(vFieldValue);
	m_id = strFieldValue;

	vFieldValue = m_pphone->GetCollect("stPhone");
	strFieldValue = (char*)_bstr_t(vFieldValue);
	m_phone = strFieldValue;


	m_pNtr.CreateInstance(__uuidof(Recordset));
	m_pNtr->Open(_bstr_t(str), con.m_pCon.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
	while (m_pNtr->adoEOF == VARIANT_FALSE)
	{
		nameValue = m_pNtr->GetCollect("stname");
		str_name = (char*)_bstr_t(nameValue);
		m_list.AddString(str_name);
		m_pNtr->MoveNext();
	}*/
}


void use_1_yggl::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	ygrz dlg_ygrz;
	dlg_ygrz.DoModal();
}


void use_1_yggl::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	yglz dlg_yglz;
	dlg_yglz.DoModal();
}
